package com.example.demo;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {
    //字体
    ListView<Object> fontList ;
    ObservableList<Object> fontData;
    //图片
    ListView<Object> imageList;
    ObservableList<Object> imageData;
    //用户
    ListView<Object> userList;
    ObservableList<Object> userData;
    /*以下为左侧菜单栏*/
    //头像
    Button avatar = new Button();
    //本地字库
    Button font_library = new Button("字库");
    //特别关心(作者)
    Button contact = new Button("关心");
    //收藏夹,可收藏喜欢的图片以及字体
    Button favourite = new Button("收藏");
    //日间模式和夜间模式
    Button day_and_night = new Button();
    //布局,网格布局和条形布局
    Button layout = new Button("布局");
    //搜索框，位于右侧界面的上部
    TextField search = new TextField();
    //查看字体
    Button font = new Button("字体");
    //查看图片
    Button image = new Button("图片");
    //查看颜色
    Button color = new Button("颜色");
    //字体被选中
    Boolean font_Checked=true;
    //图片被选中
    Boolean image_Checked=false;
    //颜色被选中
    Boolean color_Checked=false;
    //创建左侧菜单栏
    StackPane left=new StackPane();
    //创建右侧界面,预想的后续每个界面的呈现均在这个VBox中
    VBox right=new VBox();
    //搜索栏
    HBox ss=new HBox();
    //上方菜单栏
    HBox choose=new HBox();
    //栈布局
    StackPane list = new StackPane();
    //颜色版展示
    Pane color_pane = new Pane();
    //颜色选择器控件
    ColorPicker colorPicker_left = new ColorPicker(Color.rgb(255,255,255));
    ColorPicker colorPicker_right = new ColorPicker(Color.rgb(0,0,0));
    //收藏界面列表栏
    ObservableList<String> strList = FXCollections.observableArrayList("宋体","楷书","华文琥珀","华文彩云");
    ListView<String> love=new ListView<>(strList);
    //清空按键
    Button clear=new Button("×");
    //展示颜色的色板
    Circle circle = new Circle();

    //点击 布局 按钮，打开新界面
    Pane layoutPane = new Pane();
    VBox vBox = new VBox();//垂直布局
    Label labelTheme = new Label("  主题颜色");
    Label labelLayout = new Label("  首页视图");
    HBox hBoxTheme = new HBox();//标签div
    HBox hBoxLayout = new HBox();//标签div
    //放置主题颜色按钮
    HBox hBoxThemes1 = new HBox();
    HBox hBoxThemes2 = new HBox();
    //放置布局格式按钮
    HBox hBoxLayoutG = new HBox();
    //布局格式
    Button[] layoutG = new Button[]{
            new Button(),
            new Button()
    };
    //主题颜色
    Button[] themes= new Button[]{
            new Button(),
            new Button(),
            new Button(),
            new Button()};
    //按钮标签
    Label themeL1 = new Label(" 默认灰");
    Label themeL2 = new Label("             少女粉");
    Label themeL3 = new Label(" 主题黑");
    Label themeL4 = new Label("             宝石蓝");
    HBox hBoxLabel1 = new HBox(new Label("      "),themeL1,themeL2);
    HBox hBoxLabel2 = new HBox(new Label("      "),themeL3,themeL4);

    //显示颜色的值
    TextField color_left = new TextField();
    TextField color_right = new TextField();

    @Override
    public void start(Stage stage) throws IOException {

        BorderPane root = new BorderPane();
        Scene scene = new Scene(root,400,600);

        stage.setResizable(false);
        stage.setTitle("FONT & IMAGES");

        //初始化窗口
        init(root);
        font.setStyle("-fx-font-weight: bolder ;" + "-fx-background-color: #a6a6a6;");
        font_library.setId("clicked");

        //日间模式和夜间模式替换
        day_and_night.setOnAction((ActionEvent e)->{
            String urlOfDay = "file:src/main/java/com/example/demo/images/day.png";
            String urlOdNight = "file:src/main/java/com/example/demo/images/night.png";

            font_library.setId("no");
            contact.setId("no");
            favourite.setId("no");
            layout.setId("no");

            //若为日间模式,则改称夜间模式
            if (day_and_night.getId().equals("day"))
            {
                Image night = new Image(urlOdNight);
                ImageView imageView_night = new ImageView(night);
                imageView_night.setFitWidth(25);
                imageView_night.setFitHeight(25);
                day_and_night.setGraphic( imageView_night);
                day_and_night.setId("night");
                right.setStyle("-fx-background-color: #737373;");
                font.setId("button-night");
                image.setId("button-night");
                color.setId("button-night");
                list.setStyle("-fx-background-color: #737373");
                love.setId("ListView-night");
            }

            //切换到日间模式
            else
            {
                Image night = new Image(urlOfDay);
                ImageView imageView_night = new ImageView(night);
                imageView_night.setFitWidth(25);
                imageView_night.setFitHeight(25);
                day_and_night.setGraphic( imageView_night);
                day_and_night.setId("day");
                right.setStyle("-fx-background-color: #f4f4f4;");
                System.out.println("切换到白天");
                font.setId("button-day");
                image.setId("button-day");
                color.setId("button-day");
                fontList.setStyle("-fx-background-color: #f4f4f4");
                imageList.setStyle("-fx-background-color: #f4f4f4");
                list.setStyle("-fx-background-color: #f4f4f4");
                love.setId("ListView-day");
            }
        });


        //为按钮添加监听器,保证每次只选中一个
        font.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {

                font.setStyle("-fx-font-weight: bolder ;" + "-fx-background-color: #a6a6a6;");
                image.setStyle("-fx-font-weight: none;");
                color.setStyle("-fx-font-weight: none;");

                image_Checked=false;
                font_Checked=true;
                color_Checked=false;

                if (day_and_night.getId().equals("day"))
                {
                    image.setId("button-day");
                    color.setId("button-day");

                }
                else
                {
                    image.setId("button-night");
                    color.setId("button-night");
                }

            }
        });

        image.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {

                image.setStyle("-fx-font-weight: bolder ;" + "-fx-background-color: #a6a6a6;");
                font.setStyle("-fx-font-weight: none;");
                color.setStyle("-fx-font-weight: none;");

                image_Checked=true;
                font_Checked=false;
                color_Checked=false;

                if (day_and_night.getId().equals("day"))
                {
                    font.setId("button-day");
                    color.setId("button-day");

                }
                else
                {
                    font.setId("button-night");
                    color.setId("button-night");
                }
            }
        });

        color.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {

                color.setStyle("-fx-font-weight: bolder ;" + "-fx-background-color: #a6a6a6;");
                font.setStyle("-fx-font-weight: none;");
                image.setStyle("-fx-font-weight: none;");

                image_Checked=false;
                font_Checked=false;
                color_Checked=true;

                if (day_and_night.getId().equals("day"))
                {
                    font.setId("button-day");
                    image.setId("button-day");
                }
                else
                {
                    font.setId("button-night");
                    image.setId("button-night");
                }
            }
        });


        //界面的切换
        font_library.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>(){

            @Override
            public void handle(MouseEvent mouseEvent) {
                font_library.setId("clicked");
                favourite.setId("no");
                contact.setId("no");
                layout.setId("no");
                choose.setVisible(true);
                if(list.getChildren().size() != 0)
                {
                    if(image_Checked)
                    {
                        list.getChildren().remove(imageList);
                        list.getChildren().add(imageList);
                    }
                    else if(font_Checked)
                    {
                        list.getChildren().remove(fontList);
                        list.getChildren().add(fontList);
                    }
                    else if(color_Checked)
                    {
                        list.getChildren().clear();
                        list.getChildren().remove(color_pane);
                        list.getChildren().add(color_pane);
                    }
                }
            }
        });

        favourite.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>(){

            @Override
            public void handle(MouseEvent mouseEvent) {
                favourite.setId("clicked");
                font_library.setId("no");
                contact.setId("no");
                layout.setId("no");
                choose.setVisible(false);
                if(list.getChildren().size() != 0)
                {
                   //去掉一个页面，再把页面新增到栈顶，即可展示该页面
                    list.getChildren().remove(love);
                    list.getChildren().add(love);
                }
            }
        });

        contact.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>(){

            @Override
            public void handle(MouseEvent mouseEvent) {
                contact.setId("clicked");
                font_library.setId("no");
                favourite.setId("no");
                layout.setId("no");
                choose.setVisible(false);
                if(list.getChildren().size() != 0)
                {
                    //去掉一个页面，再把页面新增到栈顶，即可展示该页面
                    list.getChildren().remove(userList);
                    list.getChildren().add(userList);
                }
            }
        });


        layout.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>(){

            @Override
            public void handle(MouseEvent mouseEvent) {
                layout.setId("clicked");
                font_library.setId("no");
                contact.setId("no");
                favourite.setId("no");

                if(list.getChildren().size() != 0)
                {
                    //去掉其他页面，再把页面新增到栈顶，即可展示该页面
                    int size = list.getChildren().size();
                    for (int i =0;i<size;i++)
                    {
                        list.getChildren().remove(0);
                    }
                    //避免重复包含
                    if (!list.getChildren().contains(layoutPane))
                        list.getChildren().add(layoutPane);
                }
            }
        });

        //头像点击事件
        avatar.setOnAction(ActionEvent->{
            Images images = new Images();
            try {
                images.start(new Stage());
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        //引用css文件
        HostServices host = this.getHostServices();
        String css = host.resolveURI(host.getDocumentBase(),"src/main/java/com/example/demo/css/MainWindow.css");
        scene.getStylesheets().add(css);

        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }

    public void init(BorderPane root)
    {

        //设置头像位置
        avatar.setPrefWidth(60);
        avatar.setPrefHeight(60);
        avatar.setId("avatar");
        avatar.setLayoutX(15);
        avatar.setLayoutY(25);


        left.setPrefWidth(80);
        left.setStyle("-fx-background-color:rgb(65,65,65);-fx-border-width: 0 0 0 0;-fx-border-style: solid;");
        root.setLeft(left);


        //将以上按钮应用到stackpane布局中
        left.getChildren().addAll(avatar,font_library,contact,favourite,day_and_night,layout);
        font_library.setPrefWidth(80);
        contact.setPrefWidth(80);
        favourite.setPrefWidth(80);
        day_and_night.setPrefWidth(80);
        layout.setPrefWidth(80);
        left.setMargin(avatar, new Insets(-500,0,0,0));
        left.setMargin(font_library, new Insets(-350,0,0,0));
        left.setMargin(contact, new Insets(-250,0,0,0));
        left.setMargin(favourite, new Insets(-150,0,0,0));
        left.setMargin(day_and_night, new Insets(-50,0,0,0));
        left.setMargin(layout, new Insets(50,0,0,0));




        right.setPrefHeight(320);
        right.setStyle("-fx-border-width: 0 0 0 0;-fx-border-style: solid;");
        root.setCenter(right);


        search.setPromptText("请输入搜索:");
        search.setPrefHeight(30);
        search.setPrefWidth(260);
        ss.setMargin(search, new Insets(10));

        clear.setId("clear");
        clear.snapSpaceX(0);
        clear.snapSpaceY(0);
        ss.setAlignment(Pos.CENTER);
        clear.setMinSize(25,25);
        clear.setMaxSize(25,25);
        clear.setVisible(false);
        ss.getChildren().addAll(search,clear);
        right.getChildren().add(ss);

        //清空按钮监听
        search.textProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                String str=search.getText();
            if(str.length()!=0)
                    clear.setVisible(true);
                else
                    clear.setVisible(false);
            }
        });

        clear.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                search.clear();
                search.requestFocus();
            }
        });

        /*以下为上侧菜单栏*/

        choose.setPrefHeight(50);


        font.setId("button-day");
        font.setPrefHeight(50);
        font.setPrefWidth(70);

        image.setId("button-day");
        image.setPrefHeight(50);
        image.setPrefWidth(70);

        color.setId("button-day");
        color.setPrefHeight(50);
        color.setPrefWidth(70);
        choose.getChildren().addAll(font,image,color);
        choose.setSpacing(20);
        choose.setPadding(new Insets(10));
        right.getChildren().add(choose);

        //字体库

        Label label01 = new Label("宋体");
        Label label02 = new Label("楷书");
        Label label03 = new Label("隶书");
        Label label04 = new Label("幼圆");
        Label label05 = new Label("华文彩云");
        Label label06 = new Label("华文琥珀");
        Label label07 = new Label("方正姚体");
        Label label08 = new Label("华文新魏");
        Label label09 = new Label("方正舒体");
        label01.setId("SimSun");
        label02.setId("Xihei");
        label03.setId("LiSu");
        label04.setId("YouYuan");
        label05.setId("Caiyun");
        label06.setId("Hupo");
        label07.setId("Yaoti");
        label08.setId("Xinwei");
        label09.setId("ShuTi");
        fontData =  FXCollections.observableArrayList();
        fontData.add(label01);
        fontData.add(label02);
        fontData.add(label03);
        fontData.add(label04);
        fontData.add(label05);
        fontData.add(label06);
        fontData.add(label07);
        fontData.add(label08);
        fontData.add(label09);
        fontList = new ListView<>(fontData);
//        right.setPadding(new Insets(3));

        //给按钮设置图标,默认为日间模式
        day_and_night.setId("day");
        Image night = new Image("file:src/main/java/com/example/demo/images/day.png");
        ImageView imageView_night = new ImageView(night);
        imageView_night.setFitWidth(25);
        imageView_night.setFitHeight(25);
        day_and_night.setGraphic( imageView_night);

        //图片库
        Image [] images = new Image[]{
                new Image("file:src/main/resources/image/image1.jpg"),
                new Image("file:src/main/resources/image/image2.jpg"),
                new Image("file:src/main/resources/image/image3.png"),
                new Image("file:src/main/resources/image/image4.png"),
                new Image("file:src/main/resources/image/image5.png")
        };
        ImageView [] imageViews = new ImageView[images.length];
        for(int i=0;i<imageViews.length;i++){
            imageViews[i]= new ImageView(images[i]);
        }

        //给收藏按钮设置图标
        Image star = new Image("file:src/main/java/com/example/demo/images/star.png");
        ImageView imageView_star = new ImageView(star);
        imageView_star.setFitWidth(15);
        imageView_star.setFitHeight(15);
        contact.setGraphic( imageView_star);

        //给布局按钮设置图标
        Image layout1 = new Image("file:src/main/java/com/example/demo/images/layout.png");
        ImageView imageView_layout1 = new ImageView(layout1);
        imageView_layout1.setFitWidth(15);
        imageView_layout1.setFitHeight(15);
        layout.setGraphic( imageView_layout1);

        //给关心按钮设置图标
        Image heart = new Image("file:src/main/java/com/example/demo/images/heart.png");
        ImageView imageView_heart = new ImageView(heart);
        imageView_heart.setFitWidth(15);
        imageView_heart.setFitHeight(15);
        favourite.setGraphic( imageView_heart);

        //关心加图片
        Image [] user = new Image[]{
                new Image("file:src/main/resources/image/IMG_3458(20211231-131229).PNG"),
                new Image("file:src/main/resources/image/QQ图片20211231130419.jpg"),
                new Image("file:src/main/resources/image/IMG_3459(20211231-130825).PNG"),
        };


        ImageView [] userViews = new ImageView[user.length];
        System.out.println(userViews.length);
        for(int i=0;i<userViews.length;i++){
            userViews[i]= new ImageView(user[i]);
        }

        userData = FXCollections.observableArrayList();
        for(int i=0;i<userViews.length;i++)
        {
            userViews[i].setFitHeight(175);
            userViews[i].setFitWidth(260);
            userData.add(userViews[i]);
        }
        userList = new ListView<>(userData);
        userList.snapSpaceX(0);


        //给字库按钮设置图标
        Image brushpen = new Image("file:src/main/java/com/example/demo/images/brushpen.png");
        ImageView imageView_pen = new ImageView(brushpen);
        imageView_pen.setFitWidth(15);
        imageView_pen.setFitHeight(15);
        font_library.setGraphic( imageView_pen);

        //给头像按钮设置图标
        Image image_avatar = new Image("file:src/main/java/com/example/demo/images/avatar.png");
        ImageView imageView_avatar = new ImageView(image_avatar);
        imageView_avatar.setFitWidth(60);
        imageView_avatar.setFitHeight(60);
        avatar.setGraphic( imageView_avatar);

        imageData = FXCollections.observableArrayList();
        for(int i=0;i<imageViews.length;i++)
        {
            imageViews[i].setFitHeight(175);
            imageViews[i].setFitWidth(260);
            imageData.add(imageViews[i]);
        }
        imageList = new ListView<>(imageData);
        imageList.snapSpaceX(0);
        //添加控件入stackPane内
        list.getChildren().addAll(imageList,fontList,color_pane);
        right.getChildren().add(list);

        //设置 ”字体“ 按钮点击事件
        font.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                if(list.getChildren().size() != 0)
                {
                    //去掉其他页面，再把页面新增到栈顶，即可展示该页面
                    int size = list.getChildren().size();
                    for (int i =0;i<size;i++)
                    {
                        list.getChildren().remove(0);
                    }
                    //避免重复包含
                    if (!list.getChildren().contains(fontList))
                       list.getChildren().add(fontList);
                }
            }
        });

        //设置 ”图片“ 按钮点击事件
        image.setOnAction(event->{
            if(list.getChildren().size() != 0)
            {
                //去掉其他页面，再把页面新增到栈顶，即可展示该页面
                int size = list.getChildren().size();
                for (int i =0;i<size;i++)
                {
                    list.getChildren().remove(0);
                }
                //避免重复包含
                if (!list.getChildren().contains(imageList))
                    list.getChildren().add(imageList);
            }
        });

        //设置 布局 页面
        labelTheme.setId("labelColor");
        labelLayout.setId("labelColor");
        //div样式
        hBoxTheme.setAlignment(Pos.CENTER_LEFT);
        hBoxLayout.setAlignment(Pos.CENTER_LEFT);
        hBoxTheme.getChildren().add(labelTheme);
        hBoxLayout.getChildren().add(labelLayout);
        hBoxTheme.setId("layoutLabel");
        hBoxLayout.setId("layoutLabel");
        //设置按钮样式
        String[] id1 = new String[]{"Default","Pink","Black","Blue"};
        for(int i=0;i<2;i++)
        {
            themes[i].setId(id1[i]);
            hBoxThemes1.getChildren().add(new Label("      "));
            hBoxThemes1.getChildren().add(themes[i]);
            themes[i+2].setId(id1[i+2]);
            hBoxThemes2.getChildren().add(new Label("      "));
            hBoxThemes2.getChildren().add(themes[i+2]);
        }
        Image layoutBtn1 = new Image("file:src/main/java/com/example/demo/images/layout1.png");
        ImageView imageView_layoutBtn1 = new ImageView(layoutBtn1);
        imageView_layoutBtn1.setFitWidth(120);
        imageView_layoutBtn1.setFitHeight(100);
        Image layoutBtn2 = new Image("file:src/main/java/com/example/demo/images/layout2.png");
        ImageView imageView_layoutBtn2 = new ImageView(layoutBtn2);
        imageView_layoutBtn2.setFitWidth(120);
        imageView_layoutBtn2.setFitHeight(100);
        layoutG[0].setGraphic(imageView_layoutBtn1);
        layoutG[1].setGraphic(imageView_layoutBtn2);
        String[] id2=new String[]{"layoutOne","layoutTwo"};
        for(int i=0;i<2;i++)
        {
            layoutG[i].setId(id2[i]);
            hBoxLayoutG.getChildren().add(new Label("   "));
            hBoxLayoutG.getChildren().add(layoutG[i]);
        }

        hBoxThemes1.setSpacing(40);
        hBoxThemes2.setSpacing(40);
        hBoxLabel1.setSpacing(40);
        hBoxLabel2.setSpacing(40);
        themeL1.setId("LabelCss");
        themeL2.setId("LabelCss");
        themeL3.setId("LabelCss");
        themeL4.setId("LabelCss");


        vBox.getChildren().addAll(hBoxTheme,
                new Label(""),
                hBoxThemes1,
                new Label(""),
                hBoxLabel1,
                new Label(""),
                hBoxThemes2,
                new Label(""),
                hBoxLabel2,
                new Label(""),
                hBoxLayout,
                new Label(""),
                hBoxLayoutG);

        layoutPane.getChildren().addAll(vBox);


        //设置"颜色"按钮点击事件
        color.setOnAction(actionEvent -> {
            if (list.getChildren().size()!=0)
            {
                int size = list.getChildren().size();
                for (int i =0;i<size;i++)
               {
                   list.getChildren().remove(0);
               }

                //避免重复包含
                if (!list.getChildren().contains(color_pane))
                {
                    // 一个方向渐变
                    circle.setRadius(130);
                    circle.setLayoutX(160);
                    circle.setLayoutY(220);
                    LinearGradient linearGradient1 = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop[] {
                            new Stop(0, colorPicker_left.getValue()),
                            new Stop(1,colorPicker_right.getValue())
                    });
                    circle.setFill(linearGradient1);
                    color_pane.setPrefWidth(300);
                    color_pane.setPrefHeight(400);

                    if (!color_pane.getChildren().contains(colorPicker_left))
                    {
                        color_pane.getChildren().add(circle);
                        color_pane.getChildren().add(colorPicker_left);
                        colorPicker_right.setLayoutX(220);
                        color_pane.getChildren().add(colorPicker_right);

                        color_left.setFocusTraversable(false);
                        color_right.setFocusTraversable(false);
                        color_left.setLayoutX(0);
                        color_left.setLayoutY(460);
                        color_right.setLayoutX(220);
                        color_right.setLayoutY(460);
                        color_left.setPrefWidth(100);
                        color_right.setPrefWidth(100);
                        color_pane.getChildren().addAll(color_left,color_right);
                    }
                    list.getChildren().add(color_pane);
                }

            }
        });




        //colorPicker监听事件
        colorPicker_left.valueProperty().addListener(new ChangeListener<Color>() {
            @Override
            public void changed(ObservableValue<? extends Color> observable, Color oldValue, Color newValue) {

                LinearGradient linearGradient1 = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop[] {
                        new Stop(0, colorPicker_left.getValue()),
                        new Stop(1, colorPicker_right.getValue())
                });
                circle.setFill(linearGradient1);
                String text = "#"+Integer.toHexString((int) (colorPicker_left.getValue().getRed()*255));
                text += Integer.toHexString((int) (colorPicker_left.getValue().getBlue()*255));
                text += Integer.toHexString((int) (colorPicker_left.getValue().getGreen()*255));
                color_left.setText(text);
                color_left.requestFocus();
                color_left.selectAll();

            }
        });

        colorPicker_right.valueProperty().addListener(new ChangeListener<Color>() {
            @Override
            public void changed(ObservableValue<? extends Color> observable, Color oldValue, Color newValue) {

                LinearGradient linearGradient1 = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, new Stop[] {
                        new Stop(0, colorPicker_left.getValue()),
                        new Stop(1, colorPicker_right.getValue())
                });
                circle.setFill(linearGradient1);
                String text = "#"+Integer.toHexString((int) (colorPicker_left.getValue().getRed()*255));
                text += Integer.toHexString((int) (colorPicker_left.getValue().getBlue()*255));
                text += Integer.toHexString((int) (colorPicker_left.getValue().getGreen()*255));
                color_right.setText(text);
                color_right.requestFocus();
                color_right.selectAll();
            }
        });




    }
}